package pq3;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;


@SuppressWarnings("serial")
public class VistaCuentas extends JFrame implements ActionListener{
		
	private JList lstOp;
	private DefaultListModel dlm;
	
	private JLabel lblCte;
	private JLabel lblCteCred;
	private JLabel lblCteDeb;
	private JLabel lblCteSaldo;
	
	private JLabel lblAhorro;
	private JLabel lblAhorroCred;
	private JLabel lblAhorroDeb;
	private JLabel lblAhorroSaldo;
	
	private JLabel lblEstado;
	
	private JButton btIniciar;
	private JButton btSalir;
	
	
	
	//----------------------------
	//ACA OTRAS COSAS Q USE

	private Operacion op;
	private String lineaOp = "ACA EMPIEZA";
	private int numeroOp = 0;
	private Vector<Operacion> vOp = new Vector<Operacion>();
	private float cccred = 0;
	

	
	//----------------------------
	
	public VistaCuentas(){
			
		//---------------------------------------------
		this.setTitle("ABM LISTAS");
		this.setSize(600,400);
		this.setVisible(true);
		this.setResizable(false);
		this.setLocation(400,200);
		
		//------------------------------
		
		
		
		//--------------------------------------------------------------
		
		dlm = new DefaultListModel();
		cargarLista (dlm,lineaOp);		
		lstOp=new JList(dlm);
		lstOp.setPreferredSize(new Dimension(350,5000));
		lstOp.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		lstOp.setSelectedIndex(0);
		lstOp.addListSelectionListener(new ListSelection());
	    JScrollPane jsp=new JScrollPane(lstOp);
		jsp.setPreferredSize(new Dimension(300,300));
		
		
		//--------------------------------------------------------------
		
		lblCte = new JLabel("CUENTA CORRIENTE");
		lblCte.setBackground(Color.BLUE);
		lblCte.setForeground(Color.YELLOW);
		lblCte.setOpaque(true);
		lblCte.setPreferredSize(new Dimension(250,20));
		
		lblCteCred = new JLabel("Credito:");
		lblCteCred.setPreferredSize(new Dimension(250,20));
		
		lblCteDeb = new JLabel("Debito:");
		lblCteDeb.setPreferredSize(new Dimension(250,20));
		
		lblCteSaldo = new JLabel("Saldo");
		lblCteSaldo.setPreferredSize(new Dimension(250,20));
		
		//--------------------------------------------------------
		
		lblAhorro = new JLabel("CAJA DE AHORRO");
		lblAhorro.setPreferredSize(new Dimension(250,20));
		lblAhorro.setBackground(Color.BLUE);
		lblAhorro.setForeground(Color.YELLOW);
		lblAhorro.setOpaque(true);
		
		lblAhorroCred = new JLabel("Credito:");
		lblAhorroCred.setPreferredSize(new Dimension(250,20));
		
		lblAhorroDeb = new JLabel("Debito:");
		lblAhorroDeb.setPreferredSize(new Dimension(250,20));
		
		lblAhorroSaldo = new JLabel("Saldo");
		lblAhorroSaldo.setPreferredSize(new Dimension(250,20));
		
		//----------------------------------------------------------
		
		lblEstado = new JLabel ("Estado");
		lblEstado.setPreferredSize(new Dimension(250,20));
		
		//-----------------------------------------------------------
		
		btIniciar = new JButton ("Iniciar");
		btIniciar.setPreferredSize(new Dimension(100,20));
		
		btSalir = new JButton ("Finalizar");
		btSalir.setPreferredSize(new Dimension(100,20));
		
		//-----------------------------------------------------------
		
		JPanel p1 = new JPanel();
		p1.setLayout(new FlowLayout());
		p1.setPreferredSize(new Dimension(300,350));
		//p1.add(lstOp);
		p1.add(jsp);
		p1.add(lblEstado);
		
		JPanel p2 = new JPanel();
		p2.setLayout(new FlowLayout());
		p2.setPreferredSize(new Dimension(300,350));
		p2.add(lblCte);
		p2.add(lblCteCred);
		p2.add(lblCteDeb);
		p2.add(lblCteSaldo);
		p2.add(lblAhorro);
		p2.add(lblAhorroCred);
		p2.add(lblAhorroDeb);
		p2.add(lblAhorroSaldo);
		p2.add(btIniciar);
		p2.add(btSalir);
		
		Container c= getContentPane();
		c.setLayout(new BorderLayout());
		c.add(p1,BorderLayout.WEST);
		c.add(p2,BorderLayout.EAST);
		
		btIniciar.addActionListener(this);
		btSalir.addActionListener(this);
		
		this.pack();
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);		
	}
	
	
	
	public void cargarLista (DefaultListModel dlm, String linea){
		//CARGO LA LISTA
		dlm.addElement(linea);
		
	}
	
	class ListSelection implements ListSelectionListener {    
	    public void valueChanged(ListSelectionEvent e) {
	        //ACA OBTENGO AL OBJETO QUE SELECCIONO DE LA LISTA
	    
	    }
    }
	
	public void generarOperaciones(){
		
		System.out.println("hola2");
		new CuentaCorriente(op,this);
		new CajaAhorro(op,this);
		new Resumen(op,this);
				
	}
	
	
	public DefaultListModel devolverDLM(){
		return this.dlm;
	}
	
	public int getNumero (){
		return numeroOp + 1;
	}
	
	public void setNumero (int nro){
		this.numeroOp = nro;
	}
	
	public float getCCCred (float c){
		this.cccred = this.cccred + c;
		return cccred;
	}
	public void setCCCred (String txt){
		this.lblCteCred.setText(txt);
	}
	
	public void setCCDeb (String txt){
		this.lblCteDeb.setText(txt);
	}
	
	public void setCCSaldo (String txt){
		this.lblCteSaldo.setText(txt);
	}
	
	public void setCACred (String txt){
		this.lblAhorroCred.setText(txt);
	}
	
	public void setCADeb (String txt){
		this.lblAhorroDeb.setText(txt);
	}
	
	public void setCASaldo (String txt){
		this.lblAhorroSaldo.setText(txt);
	}

	public void addVector (Operacion op){
		vOp.addElement(op);
	}
	public Vector<Operacion> getVector (){
		
		return vOp;		
	}



	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equalsIgnoreCase("Iniciar")){
			System.out.println("hola");
			generarOperaciones();
			
		}
		if(e.getActionCommand().equalsIgnoreCase("Finalizar")){
			System.exit(0);
		}
		
	}

}

